import { PrimeVueResolver } from '@primevue/auto-import-resolver';
import vue from '@vitejs/plugin-vue';
import { fileURLToPath, URL } from 'node:url';
import Components from 'unplugin-vue-components/vite';
import { defineConfig } from 'vitest/config';

export default defineConfig({
  plugins: [
    vue(),
    Components({
      resolvers: [PrimeVueResolver()],
      dts: false // 测试环境不需要类型文件
    })
  ],

  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },

  test: {
    // 测试环境配置
    environment: 'happy-dom',

    // 全局测试设置
    globals: true,

    // 测试文件匹配模式
    include: [
      'src/**/__tests__/**/*.{test,spec}.{js,jsx,ts,tsx,vue}',
      'src/**/*.{test,spec}.{js,jsx,ts,tsx,vue}',
      'tests/**/*.{test,spec}.{js,jsx,ts,tsx,vue}'
    ],

    // 排除的文件
    exclude: [
      'node_modules',
      'dist',
      '.idea',
      '.git',
      '.cache'
    ],

    // 覆盖率配置
    coverage: {
      provider: 'v8',
      reporter: ['text', 'json', 'html'],
      exclude: [
        'node_modules/',
        'src/assets/',
        'src/**/*.d.ts',
        'src/**/types.ts',
        'src/**/__tests__/**',
        'src/**/*.test.*',
        'src/**/*.spec.*',
        'dist/',
        'coverage/',
        '*.config.js',
        '*.config.mjs',
        '*.config.ts'
      ],
      thresholds: {
        statements: 70,
        branches: 70,
        functions: 70,
        lines: 70
      }
    },

    // 设置测试文件
    setupFiles: ['./tests/setup.js'],

    // 测试超时时间
    testTimeout: 10000,

    // 钩子超时时间
    hookTimeout: 10000,

    // 静默模式配置
    silent: false,

    // 记者配置
    reporter: ['verbose'],

    // 并发配置
    threads: true,
    maxThreads: 4,
    minThreads: 1,

    // 监视模式排除
    watchExclude: [
      'node_modules/**',
      'dist/**',
      'coverage/**'
    ],

    // 模拟配置
    deps: {
      inline: [
        '@vue',
        'primevue'
      ]
    }
  },

  // 定义全局变量
  define: {
    __VUE_OPTIONS_API__: true,
    __VUE_PROD_DEVTOOLS__: false,
    __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false
  }
});
